﻿using System;

namespace Effects.Effects.Tools
{
    /// <summary>
    ///  Implementation of saw wave oscillator.
    /// </summary>
    public class SawOscilator : Oscillator
    {
        /// <summary>
        ///     Gets ocillator's value at given time.  Overridden to behave as saw oscillator.
        /// </summary>
        /// <param name="time"> time of the oscilation </param>
        /// <returns> Value at given time. </returns>
        public override double Amplitude(double time)
        {
            while (time > period)
                time -= period;

            return time / period;
        }

        /// <summary>
        ///  Makes stepTime advance of oscillator's time and returns current value of oscillation.  Overridden to behave as saw oscillator.
        /// </summary>
        /// <param name="stepTime"> Length of a step that oscillator advances in time. </param>
        /// <returns> Current value of an oscillator after the step.</returns>
        public override double Step(double stepTime)
        {
            time += stepTime;
            while (time > period)
                time -= period;
            return time / period;
        }
    }
}